#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <unordered_map>
#define int long long
using namespace std;

struct car
{
    int d, v, a;
};

vector<car> cars;
vector<vector<int>> map(1000006);
vector<pair<int, int>> regions;
vector<bool> flag(1000006);
vector<bool> dtflag(1000006);
vector<signed> dt(1000006);

void Main()
{
    vector<signed> ps(1000006);
    cars.clear();
    map.clear();
    fill(dt.begin(), dt.end(), 0);
    regions.clear();
    int n, m, l, v;
    cin >> n >> m >> l >> v;
    for (int i = 0; i < n; i++)
    {
        int d, v, a;
        cin >> d >> v >> a;
        cars.push_back({d, v, a});
    }
    for (int i = 0; i < m; i++)
    {
        int p;
        cin >> p;
        ps[p]++;
        dt.push_back(p);
    }
    for (int i = 1; i <= 1000006; i++)
    {
        ps[i] += ps[i - 1];
    }
    int sum = 0;
    for (auto c : cars) // calculate speed
    {
        if (c.a == 0 && c.v > v && ps[c.d] != ps[l])
        {
            sum++;
            regions.push_back({c.d, l});
        }
        else if (c.a != 0)
        {
            double s = double(v * v - c.v * c.v) / (2.0 * c.a) + c.d;
            if (c.a < 0 && c.v <= v)
                ;
            else if (c.a > 0 && ps[ceil(s)] != ps[l])
            {
                sum++;
                regions.push_back({ceil(s), l});
            }
            else if (c.a < 0 && ps[floor(s)] != ps[c.d])
            {
                sum++;
                regions.push_back({floor(s), l});
            }
        }
    }
    cout << sum << endl;
}

signed main()
{
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t; // 20
    cin >> t;
    while (t--)
    {
        Main();
    }
    return 0;
}